package com.kurumi.controller;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.kurumi.config.MyConfig;
import com.kurumi.pojo.MedicalRecord;
import com.kurumi.pojo.RespondResult;
import com.kurumi.pojo.coding.BasicInfo;
import com.kurumi.pojo.coding.CostInfo;
import com.kurumi.pojo.coding.CureInfo;
import com.kurumi.pojo.coding.DiseaseDiagInfo;
import com.kurumi.pojo.coding.DiseaseDiagRecord;
import com.kurumi.pojo.coding.DrugAllergyInfo;
import com.kurumi.pojo.coding.InfectionInfo;
import com.kurumi.pojo.coding.InfusionBloodInfo;
import com.kurumi.pojo.coding.IntensiveCareInfo;
import com.kurumi.pojo.coding.MedicalVentilatorInfo;
import com.kurumi.pojo.coding.NurseInfo;
import com.kurumi.pojo.coding.OperateInfo;
import com.kurumi.pojo.coding.OperateRecord;
import com.kurumi.pojo.coding.PathologyDiseaseDiagRecord;
import com.kurumi.pojo.coding.TransferDeptInfo;
import com.kurumi.query.MedicalRecordQuery;
import com.kurumi.query.StatisticsAnalysisQuery;
import com.kurumi.service.BaseInfoService;
import com.kurumi.service.InterfaceMedicalRecord1Service;
import com.kurumi.service.MedicalRecordCodingService;
import com.kurumi.service.MedicalRecordService;
import com.kurumi.service.MedicalRecordTraceService;
import com.kurumi.util.DateUtil;
import com.kurumi.util.FileUtil;
import com.kurumi.util.HttpClientUtil;
import com.kurumi.util.JsonUtil;
import com.kurumi.util.ObjectUtils;
import com.kurumi.util.PDFUtil;
import com.kurumi.util.StringUtil;
import com.kurumi.util.WaterMarkUtil;

@Controller
@RequestMapping("/medical_record_coding")
public class MedicalRecordCodingController {

	@Autowired
	private MyConfig myConfig;

	@Autowired
	private BaseInfoService baseInfoService;

	@Autowired
	private MedicalRecordService medicalRecordService;

	@Autowired
	private MedicalRecordCodingService medicalRecordCodingService;

	@Autowired
	private MedicalRecordTraceService medicalRecordTraceService;

	@Autowired
	private InterfaceMedicalRecord1Service interfaceMedicalRecord1Service;

	@GetMapping("/query_home_page")
	public String queryHomePage(Model model){
		return "coding/query_home_page";
	}

	@GetMapping("/ajax_query_home_page")
	@ResponseBody
	public RespondResult ajaxQueryHomePage(MedicalRecordQuery params){
		RespondResult respondResult = null;

		try{
			List<Map<String,Object>> medicalRecords = new ArrayList<Map<String,Object>>();
			int count = 0;
			/*params.setPageSize(null);
			if(!params.queryUnEncodingEmpty()){
				medicalRecords = medicalRecordService.getMedicalRecordOfHomePage(params);
				System.err.println(medicalRecords.size());
				int i = 0;
				for (Map<String, Object> medicalRecord : medicalRecords) {
					try{
						String visitGuid = ObjectUtils.getStringValue(medicalRecord.get("visit_guid"));
						String onlyId = ObjectUtils.getStringValue(medicalRecord.get("only_id"));
						String mrId = ObjectUtils.getStringValue(medicalRecord.get("mr_id"));
						String visitNumber = ObjectUtils.getStringValue(medicalRecord.get("visit_number"));
						Map<String, String> param = new HashMap<String, String>();
						param.put("visitGuid", visitGuid);
						param.put("mrId", mrId);
						param.put("visitNumber", visitNumber);
						param.put("onlyId", onlyId);
						if(onlyId != null){
							if(!(onlyId.contains("N") && onlyId.length() ==8)){
								String userJson = HttpClientUtil.doGet(myConfig.getRemoteInterfaceUrl()+"interface_data_qf_dr/remote_extract_interface_cost", param);
								if(userJson != null){
									JSONObject userMap =JSONObject.parseObject(userJson);
									boolean success = userMap.getBoolean("success");
									if(success){

										Map<String, Object> jsonMap = (Map<String, Object>)userMap.get("datas");
										Map<String, Object> costMap = (Map<String, Object>)jsonMap.get("costInfo");
										count = interfaceMedicalRecord1Service.extractInterfaceMedicalRecordOfCost(visitGuid, costMap);
										if(count != 1){
											System.err.println(onlyId+"提取费用失败");
										}
									}else{
										String stateMessage = userMap.getString("stateMessage");
										if(stateMessage == null){
											stateMessage = "访问接口应用失败";
										}
										System.err.println(onlyId+"提取费用失败");
									}
								}else{
									System.err.println(onlyId+"提取费用失败");
								}
							}
						}

					}catch (Exception e) {
						// TODO: handle exception
						e.printStackTrace();
					}
					i++;
					System.err.println(i);
				}
			}*/
			/*params.setPageSize(null);
			if(!params.queryUnEncodingEmpty()){
				medicalRecords = medicalRecordService.getMedicalRecordOfHomePage(params);
				System.err.println(medicalRecords.size());
				int i = 0;
				for (Map<String, Object> medicalRecord : medicalRecords) {
					try{
						String visitGuid = ObjectUtils.getStringValue(medicalRecord.get("visit_guid"));
						medicalRecordCodingService.codingFinish1(visitGuid);
					}catch (Exception e) {
						// TODO: handle exception
						e.printStackTrace();
					}
					i++;
					System.err.println(i);
				}
			}*/
			if(!params.queryUnEncodingEmpty()){
//				medicalRecords = medicalRecordService.getMedicalRecordOfHomePage(params);
//				count = medicalRecordService.getMedicalRecordCountOfHomePage(params);
				medicalRecords = medicalRecordService.getMedicalRecordHomePage(params);
				count = medicalRecordService.getMedicalRecordCountHomePage(params);
			}

			params.setTotalCounts(count);
			params.setQueryDatas(medicalRecords);
			respondResult = new RespondResult(true, RespondResult.successCode, null, params);
		}catch (Exception e) {
			// TODO: handle exception
			respondResult = new RespondResult(false, RespondResult.errorCode, e.getMessage(), params);
		}

		return respondResult;
	}


	@GetMapping("/edit_index_info")
	public String editHomePageIndexForm(String visitGuid,Model model){
		model.addAttribute("visitGuid", visitGuid);
		List<Map<String,Object>> medicalRecords = medicalRecordService.getMedicalRecordByVisitGuid(visitGuid);
		if(medicalRecords.size() == 0){
			RespondResult respondResult = new RespondResult(false,"404","网址错误，资源不存在",null);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
		}else{
			Map<String,Object> medicalRecord = medicalRecords.get(0);
			RespondResult respondResult = new RespondResult(true,"302","",medicalRecord);
			try{
				medicalRecordTraceService.insertCodingPageTrace(visitGuid);
			}catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
		}
		return "coding/edit_index_info";
	}

	@GetMapping("/edit_basic_info_form")
	public String editBasicInfoForm(String visitGuid,Model model){
		Map<String, List<Map<String, Object>>> baseInfo = baseInfoService.getBaseDataOfBasicInfo();//获取字典信息
		String baseInfoJson = JsonUtil.objectToJson(baseInfo);
		model.addAttribute("baseInfoJson", baseInfoJson);
		model.addAttribute("visitGuid", visitGuid);
		/*String filePath = myConfig.getJsonRecourcePath() + StringUtil.getLocalPath(visitGuid);
		String fileName = visitGuid + ".json";

		String jsonData = FileUtil.readFile(filePath, fileName);*/
		List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(visitGuid);
		Map<String, Object> basicInfo = null;
		if(!jsonDatas.isEmpty()){
			Map<String, Object> jsonMap = new HashMap<String, Object>();
			jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
			basicInfo = (Map<String, Object>)jsonMap.get("basicInfo");
			String birthday = MapUtils.getString(basicInfo, "birthday");
			basicInfo.put("birthdayStr", StringUtils.isBlank(birthday)?null:birthday);
		}
		if(basicInfo == null){
			basicInfo = new HashMap<String, Object>();
			MedicalRecord medicalRecord = medicalRecordService.selectMedicalRecordByPrimaryKey(visitGuid);

			String patientName = medicalRecord.getPatientName();
			basicInfo.put("patientName",patientName);

			String sexCode = medicalRecord.getSexCode();
			basicInfo.put("sexCode",sexCode);

			String sexName = medicalRecord.getSexName();
			basicInfo.put("sexName",sexName);

			Date birthday = medicalRecord.getBirthday();
			if(birthday != null){
				basicInfo.put("birthday", DateUtil.dateFormat(birthday));
			}
			String documentTypeCode = medicalRecord.getDocumentTypeCode();
			basicInfo.put("documentTypeCode",documentTypeCode);

			String documentTypeName = medicalRecord.getDocumentTypeName();
			basicInfo.put("documentTypeName",documentTypeName);

			String idNumber = medicalRecord.getIdNumber();
			basicInfo.put("idNumber",idNumber);


			String inDeptCode = medicalRecord.getInDeptCode();
			basicInfo.put("inDeptCode",inDeptCode);

			String inDeptName = medicalRecord.getInDeptName();
			basicInfo.put("inDeptName",inDeptName);

			Date inHospitalDateTime = medicalRecord.getInHospitalDateTime();
			if(inHospitalDateTime != null){
				basicInfo.put("inHospitalDateTime", DateUtil.dateFormat(DateUtil.DATE_TIME_FORMATE,inHospitalDateTime));
			}


			Date outHospitalDateTime = medicalRecord.getOutHospitalDateTime();
			if(outHospitalDateTime != null){
				basicInfo.put("outHospitalDateTime", DateUtil.dateFormat(DateUtil.DATE_TIME_FORMATE,outHospitalDateTime));
			}



			String outDeptCode = medicalRecord.getOutDeptCode();
			basicInfo.put("outDeptCode",outDeptCode);

			String outDeptName = medicalRecord.getOutDeptName();
			basicInfo.put("outDeptName",outDeptName);

			String outHospitalTypeCode = medicalRecord.getOutHospitalTypeCode();
			basicInfo.put("outHospitalTypeCode",outHospitalTypeCode);

			String outHospitalTypeName = medicalRecord.getOutHospitalTypeName();
			basicInfo.put("outHospitalTypeName",outHospitalTypeName);

			String mrId = medicalRecord.getMrId();
			basicInfo.put("mrId",mrId);

			String onlyId = medicalRecord.getOnlyId();
			basicInfo.put("onlyId",onlyId);

			Integer visitNumber = medicalRecord.getVisitNumber();
			basicInfo.put("visitNumber",visitNumber);
		}


		String basicInfoJson = JsonUtil.objectToJson(basicInfo);
		model.addAttribute("basicInfoJson", basicInfoJson);
		model.addAttribute("basicInfo", basicInfo);
		return "coding/edit_basic_info";
	}


	@SuppressWarnings("unchecked")
	@PostMapping("/edit_basic_info")
	public String editBasicInfo(BasicInfo basicInfo,HttpServletRequest request,Model model){

		try {
			String birthdayStr = request.getParameter("birthdayStr");
			if(StringUtils.isBlank(birthdayStr)){
				basicInfo.setBirthday(null);

			}else{
				try {
					basicInfo.setBirthday(DateUtil.dateParse("yyyy-MM-dd", birthdayStr));
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			basicInfo.getNativePlaceRegionalism().initProvinceCityCountyCode();
			basicInfo.setNativePlace(basicInfo.getNativePlaceRegionalism().getFullAddress());
			basicInfo.getBirthRegionalism().initProvinceCityCountyCode();
			basicInfo.setBirthAddress(basicInfo.getBirthRegionalism().getFullAddress());

			basicInfo.getRegisteredAddressRegionalism().initProvinceCityCountyCode();
			basicInfo.setRegisteredAddress(basicInfo.getRegisteredAddressRegionalism().getFullAddress());
			basicInfo.getPermanentAddressRegionalism().initProvinceCityCountyCode();
			basicInfo.setPermanentAddress(basicInfo.getPermanentAddressRegionalism().getFullAddress());

			basicInfo.getWorkUnitRegionalism().initProvinceCityCountyCode();
			basicInfo.setWorkUnitAddress(basicInfo.getWorkUnitRegionalism().getFullAddress());

			basicInfo.getLinkManAddressRegionalism().initProvinceCityCountyCode();
			basicInfo.setLinkManAddress(basicInfo.getLinkManAddressRegionalism().getFullAddress());

			if(basicInfo.getYearOfAge() == null && basicInfo.getMonthOfAge() ==null && basicInfo.getDayOfAge() == null){
				if(basicInfo.getBirthday() != null && basicInfo.getInHospitalDateTime() != null){
					Map<String, Integer> dateDiff = DateUtil.getYearMonthDay(basicInfo.getBirthday(), basicInfo.getInHospitalDateTime());
					if(dateDiff.get("year") != null){
						basicInfo.setYearOfAge(new BigDecimal(dateDiff.get("year")));
					}else if(dateDiff.get("month") != null){
						basicInfo.setMonthOfAge(new BigDecimal(dateDiff.get("month")));
					}else if(dateDiff.get("day") != null){
						basicInfo.setDayOfAge(new BigDecimal(dateDiff.get("day")));
					}
				}
			}

			if(basicInfo.getInHospitalDayNumber() == null){
				if(basicInfo.getInHospitalDateTime() != null && basicInfo.getOutHospitalDateTime() != null){

					try {
						int inHospitalDayNumber = DateUtil.getDaysBetween(basicInfo.getInHospitalDateTime(), basicInfo.getOutHospitalDateTime());
						basicInfo.setInHospitalDayNumber(new BigDecimal(inHospitalDayNumber));
					} catch (ParseException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}

				}
			}

			String filePath = myConfig.getJsonRecourcePath() + StringUtil.getLocalPath(basicInfo.getVisitGuid())+basicInfo.getVisitGuid()+"\\";
			String versionFilePath = filePath+"version\\";
			String fileName = basicInfo.getVisitGuid() + ".json";
			String versionFileName = basicInfo.getVisitGuid()+"-" + DateUtil.dateFormat("yyyyMMddHHmmssssss", new Date()) + ".json";
			/*String jsonData = FileUtil.readFile(filePath, fileName);*/
			List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(basicInfo.getVisitGuid());
			Map<String, Object> jsonMap = new HashMap<String, Object>();
			if(!jsonDatas.isEmpty()){
				jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
				if(jsonMap == null){
					jsonMap = new HashMap<String, Object>();
				}
			}

			Subject subject=SecurityUtils.getSubject();
			Session session = subject.getSession();
			Map<String, Object> currentUser = (Map<String, Object>)session.getAttribute("currentUser");
			String userCode =(String)currentUser.get("user_code");
			String userName =(String)currentUser.get("user_name");
			jsonMap.put("userCode", userCode);
			jsonMap.put("userName", userName);
			jsonMap.put("basicInfo", basicInfo);
			String jsonMapJson = JsonUtil.objectToJson(jsonMap);
			FileUtil.createOrEditFile(jsonMapJson, filePath, fileName);
			FileUtil.createOrEditFile(jsonMapJson, versionFilePath, versionFileName);
			medicalRecordCodingService.editBasicInfo(basicInfo.getVisitGuid(), basicInfo, jsonMap);
			RespondResult respondResult = new RespondResult(true,"200","保存成功",null);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
			jsonMap = JsonUtil.jsonToPojo(jsonMapJson, Map.class);
			Map<String, List<Map<String, Object>>> baseInfo = baseInfoService.getBaseDataOfBasicInfo();
			String baseInfoJson = JsonUtil.objectToJson(baseInfo);
			model.addAttribute("baseInfoJson", baseInfoJson);
			model.addAttribute("visitGuid", basicInfo.getVisitGuid());
			Map<String, Object> basicInfoMap = (Map<String, Object>)jsonMap.get("basicInfo");
			String birthday = MapUtils.getString(basicInfoMap, "birthday");
			basicInfoMap.put("birthdayStr", StringUtils.isBlank(birthday)?null:birthday);
			String basicInfoJson = JsonUtil.objectToJson(basicInfoMap);
			model.addAttribute("basicInfoJson", basicInfoJson);
			model.addAttribute("basicInfo",  basicInfoMap);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			RespondResult respondResult = new RespondResult(false,"500","保存失败",null);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
		}

		return "coding/edit_basic_info";
	}


	@GetMapping("/edit_cure_info_form")
	public String editCureInfoForm(String visitGuid,Model model){
		Map<String, List<Map<String, Object>>> baseInfo = baseInfoService.getBaseDataOfCureInfo();
		String baseInfoJson = JsonUtil.objectToJson(baseInfo);
		model.addAttribute("baseInfoJson", baseInfoJson);
		model.addAttribute("visitGuid", visitGuid);
		/*String filePath = myConfig.getJsonRecourcePath() + StringUtil.getLocalPath(visitGuid);
		String fileName = visitGuid + ".json";
		String jsonData = FileUtil.readFile(filePath, fileName);*/
		List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(visitGuid);
		Map<String, Object> cureInfo = new HashMap<String, Object>();
		if(!jsonDatas.isEmpty()){
			Map<String, Object> jsonMap = new HashMap<String, Object>();
			jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
			cureInfo = (Map<String, Object>)jsonMap.get("cureInfo");
			if(cureInfo == null){
				cureInfo = new HashMap<String, Object>();
			}
		}


		String cureInfoJson = JsonUtil.objectToJson(cureInfo);
		model.addAttribute("cureInfo", cureInfo);
		model.addAttribute("basicInfoJson", cureInfoJson);
		model.addAttribute("cureInfoJson", cureInfoJson);
		return "coding/edit_cure_info";
	}


	@SuppressWarnings("unchecked")
	@PostMapping("/edit_cure_info")
	public String editCureInfo(CureInfo cureInfo,HttpServletRequest request,Model model){

		try {
			String filePath = myConfig.getJsonRecourcePath() + StringUtil.getLocalPath(cureInfo.getVisitGuid())+cureInfo.getVisitGuid()+"\\";
			String versionFilePath = filePath+"version\\";
			String fileName = cureInfo.getVisitGuid() + ".json";
			String versionFileName = cureInfo.getVisitGuid()+"-" + DateUtil.dateFormat("yyyyMMddHHmmssssss", new Date()) + ".json";
			/*String jsonData = FileUtil.readFile(filePath, fileName);*/
			List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(cureInfo.getVisitGuid());
			Map<String, Object> jsonMap = new HashMap<String, Object>();
			if(!jsonDatas.isEmpty()){
				jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
				if(jsonMap == null){
					jsonMap = new HashMap<String, Object>();
				}
			}

			Subject subject=SecurityUtils.getSubject();
			Session session = subject.getSession();
			Map<String, Object> currentUser = (Map<String, Object>)session.getAttribute("currentUser");
			String userCode =(String)currentUser.get("user_code");
			String userName =(String)currentUser.get("user_name");
			jsonMap.put("userCode", userCode);
			jsonMap.put("userName", userName);
			jsonMap.put("cureInfo", cureInfo);
			String jsonMapJson = JsonUtil.objectToJson(jsonMap);
			FileUtil.createOrEditFile(jsonMapJson, filePath, fileName);
			FileUtil.createOrEditFile(jsonMapJson, versionFilePath, versionFileName);
			medicalRecordCodingService.editCureInfo(cureInfo.getVisitGuid(), cureInfo, jsonMap);
			RespondResult respondResult = new RespondResult(true,"200","保存成功",null);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
			jsonMap = JsonUtil.jsonToPojo(jsonMapJson, Map.class);
			Map<String, List<Map<String, Object>>> baseInfo = baseInfoService.getBaseDataOfCureInfo();
			String baseInfoJson = JsonUtil.objectToJson(baseInfo);
			model.addAttribute("baseInfoJson", baseInfoJson);
			model.addAttribute("visitGuid", cureInfo.getVisitGuid());
			Map<String, Object> cureInfoMap = (Map<String, Object>)jsonMap.get("cureInfo");
			String cureInfoJson = JsonUtil.objectToJson(cureInfoMap);
			model.addAttribute("cureInfoJson", cureInfoJson);
			model.addAttribute("cureInfo",  cureInfoMap);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			RespondResult respondResult = new RespondResult(false,"500","保存失败",null);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
		}

		return "coding/edit_cure_info";
	}


	@SuppressWarnings("unchecked")
	@GetMapping("/edit_disease_diag_info_form")
	public String editDiseaseDiagInfoForm(String visitGuid,Model model){
		Map<String, List<Map<String, Object>>> baseInfo = baseInfoService.getBaseDataOfDiagInfo();
		String baseInfoJson = JsonUtil.objectToJson(baseInfo);
		model.addAttribute("baseInfoJson", baseInfoJson);
		model.addAttribute("visitGuid", visitGuid);
		/*String filePath = myConfig.getJsonRecourcePath() + StringUtil.getLocalPath(visitGuid);
		String fileName = visitGuid + ".json";
		String jsonData = FileUtil.readFile(filePath, fileName);*/
		List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(visitGuid);
		Map<String, Object> diseaseDiagInfo =  new HashMap<String, Object>();
		if(!jsonDatas.isEmpty()){
			Map<String, Object> jsonMap = new HashMap<String, Object>();
			jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
			diseaseDiagInfo = (Map<String, Object>)jsonMap.get("hqmsDiseaseDiagInfo");
			if(diseaseDiagInfo == null){
				diseaseDiagInfo = new HashMap<String, Object>();
			}
		}

		model.addAttribute("diseaseDiagInfo", diseaseDiagInfo);
		String diseaseDiagInfoJson = JsonUtil.objectToJson(diseaseDiagInfo);
		model.addAttribute("diseaseDiagInfoJson", diseaseDiagInfoJson);
		return "coding/edit_disease_diag_info";
	}


	@SuppressWarnings("unchecked")
	@PostMapping("/edit_disease_diag_info")
	public String editDiseaseDiagInfo(DiseaseDiagInfo diseaseDiagInfo,HttpServletRequest request,Model model){

		try {

			String filePath = myConfig.getJsonRecourcePath() + StringUtil.getLocalPath(diseaseDiagInfo.getVisitGuid())+diseaseDiagInfo.getVisitGuid()+"\\";
			String versionFilePath = filePath+"version\\";
			String fileName = diseaseDiagInfo.getVisitGuid() + ".json";
			String versionFileName = diseaseDiagInfo.getVisitGuid()+"-" + DateUtil.dateFormat("yyyyMMddHHmmssssss", new Date()) + ".json";

			/*String jsonData = FileUtil.readFile(filePath, fileName);*/
			List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(diseaseDiagInfo.getVisitGuid());
			Map<String, Object> jsonMap = new HashMap<String, Object>();
			if(!jsonDatas.isEmpty()){
				jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
				if(jsonMap == null){
					jsonMap = new HashMap<String, Object>();
				}
			}
			diseaseDiagInfo.clearEmpty();
			Collections.sort(diseaseDiagInfo.getDiseaseDiagRecords(),
				new DiseaseDiagRecord.DiseaseDiagRecordComparator());
			diseaseDiagInfo.getOutpatientDiagRecord().setDiseaseDiagVersion(myConfig.getCurrentDiseaseVersion());
			diseaseDiagInfo.getMainDiagRecord().setDiseaseDiagVersion(myConfig.getCurrentDiseaseVersion());

			for (DiseaseDiagRecord otherDiag : diseaseDiagInfo.getDiseaseDiagRecords()) {
				otherDiag.setDiseaseDiagVersion(myConfig.getCurrentDiseaseVersion());
			}
			for (DiseaseDiagRecord damageAndVenenationDiag : diseaseDiagInfo.getDamageAndVenenationDiagRecords()) {
				damageAndVenenationDiag.setDiseaseDiagVersion(myConfig.getCurrentDiseaseVersion());
			}
			for (PathologyDiseaseDiagRecord pathologyDiag : diseaseDiagInfo.getPathologyDiagRecords()) {
				pathologyDiag.setDiseaseDiagVersion(myConfig.getCurrentDiseaseVersion());
			}
			Subject subject=SecurityUtils.getSubject();
			Session session = subject.getSession();
			Map<String, Object> currentUser = (Map<String, Object>)session.getAttribute("currentUser");
			String userCode =(String)currentUser.get("user_code");
			String userName =(String)currentUser.get("user_name");
			jsonMap.put("userCode", userCode);
			jsonMap.put("userName", userName);
			jsonMap.put("hqmsDiseaseDiagInfo", diseaseDiagInfo);
			String jsonMapJson = JsonUtil.objectToJson(jsonMap);
			FileUtil.createOrEditFile(jsonMapJson, filePath, fileName);
			FileUtil.createOrEditFile(jsonMapJson, versionFilePath, versionFileName);
			jsonMap = JsonUtil.jsonToPojo(jsonMapJson, Map.class);
			medicalRecordCodingService.editDiseaseDiagInfo(diseaseDiagInfo.getVisitGuid(), diseaseDiagInfo, jsonMap);
			Map<String, List<Map<String, Object>>> baseInfo = baseInfoService.getBaseDataOfDiagInfo();
			String baseInfoJson = JsonUtil.objectToJson(baseInfo);
			model.addAttribute("baseInfoJson", baseInfoJson);
			model.addAttribute("visitGuid", diseaseDiagInfo.getVisitGuid());
			model.addAttribute("diseaseDiagInfo", diseaseDiagInfo);
			String diseaseDiagInfoJson = JsonUtil.objectToJson(diseaseDiagInfo);
			model.addAttribute("diseaseDiagInfoJson", diseaseDiagInfoJson);
			RespondResult respondResult = new RespondResult(true,"200","保存成功",null);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			RespondResult respondResult = new RespondResult(false,"500","保存失败",null);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
		}

		return "coding/edit_disease_diag_info";
	}


	@SuppressWarnings("unchecked")
	@GetMapping("/edit_operate_info_form")
	public String editOperateInfoForm(String visitGuid,Model model){
		Map<String, List<Map<String, Object>>> baseInfo = baseInfoService.getBaseDataOfOperateInfo();
		String baseInfoJson = JsonUtil.objectToJson(baseInfo);
		model.addAttribute("baseInfoJson", baseInfoJson);
		model.addAttribute("visitGuid", visitGuid);
		/*String filePath = myConfig.getJsonRecourcePath() + StringUtil.getLocalPath(visitGuid);
		String fileName = visitGuid + ".json";
		String jsonData = FileUtil.readFile(filePath, fileName);*/
		List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(visitGuid);

		Map<String, Object> operateInfo =new HashMap<String, Object>();
		if(!jsonDatas.isEmpty()){
			Map<String, Object> jsonMap = new HashMap<String, Object>();
			jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
			operateInfo = (Map<String, Object>)jsonMap.get("hqmsOperateInfo");
			if(operateInfo == null){
				operateInfo = new HashMap<String, Object>();
			}
		}

		model.addAttribute("operateInfo", operateInfo);
		String operateInfoJson = JsonUtil.objectToJson(operateInfo);
		model.addAttribute("operateInfoJson", operateInfoJson);
		return "coding/edit_operate_info";
	}

	@SuppressWarnings("unchecked")
	@PostMapping("/edit_operate_info")
	public String editOperateInfo(OperateInfo operateInfo,HttpServletRequest request,Model model){
		try {

			String filePath = myConfig.getJsonRecourcePath() + StringUtil.getLocalPath(operateInfo.getVisitGuid())+operateInfo.getVisitGuid()+"\\";
			String versionFilePath = filePath+"version\\";
			String fileName = operateInfo.getVisitGuid() + ".json";
			String versionFileName = operateInfo.getVisitGuid()+"-" + DateUtil.dateFormat("yyyyMMddHHmmssssss", new Date()) + ".json";

			/*String jsonData = FileUtil.readFile(filePath, fileName);*/
			List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(operateInfo.getVisitGuid());
			Map<String, Object> jsonMap = new HashMap<String, Object>();
			if(!jsonDatas.isEmpty()){
				jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
				if(jsonMap == null){
					jsonMap = new HashMap<String, Object>();
				}
			}
			operateInfo.clearEmpty();
			Collections.sort(operateInfo.getOperateRecords(),
					new OperateRecord.OperateRecordComparator());
			for (OperateRecord operateRecord : operateInfo.getOperateRecords()) {
				operateRecord.setOperateVersion(myConfig.getCurrentSurgeryVersion());
			}
			Subject subject=SecurityUtils.getSubject();
			Session session = subject.getSession();
			Map<String, Object> currentUser = (Map<String, Object>)session.getAttribute("currentUser");
			String userCode =(String)currentUser.get("user_code");
			String userName =(String)currentUser.get("user_name");
			jsonMap.put("userCode", userCode);
			jsonMap.put("userName", userName);
			jsonMap.put("hqmsOperateInfo", operateInfo);
			String jsonMapJson = JsonUtil.objectToJson(jsonMap);
			FileUtil.createOrEditFile(jsonMapJson, filePath, fileName);
			FileUtil.createOrEditFile(jsonMapJson, versionFilePath, versionFileName);
			medicalRecordCodingService.editOperateInfo(operateInfo.getVisitGuid(), operateInfo, jsonMap);
			jsonMap = JsonUtil.jsonToPojo(jsonMapJson, Map.class);
			Map<String, List<Map<String, Object>>> baseInfo = baseInfoService.getBaseDataOfOperateInfo();
			String baseInfoJson = JsonUtil.objectToJson(baseInfo);
			model.addAttribute("baseInfoJson", baseInfoJson);
			model.addAttribute("visitGuid", operateInfo.getVisitGuid());

			Map<String, Object> operateInfoMap = (Map<String, Object>)jsonMap.get("hqmsOperateInfo");
			String operateInfoJson = JsonUtil.objectToJson(operateInfoMap);
			model.addAttribute("operateInfo", operateInfoMap);

			model.addAttribute("operateInfoJson", operateInfoJson);
			RespondResult respondResult = new RespondResult(true,"200","保存成功",null);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			RespondResult respondResult = new RespondResult(false,"500","保存失败",null);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
		}

		return "coding/edit_operate_info";
	}


	@GetMapping("/edit_infusion_blood_info_form")
	public String editInfusionBloodInfoForm(String visitGuid,Model model){

		model.addAttribute("visitGuid", visitGuid);
		Map<String, List<Map<String, Object>>> baseInfo = baseInfoService.getBaseDataOfInfusionBloodInfo();
		String baseInfoJson = JsonUtil.objectToJson(baseInfo);
		model.addAttribute("baseInfoJson", baseInfoJson);
		List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(visitGuid);

		Map<String, Object> infusionBloodInfo = new HashMap<String, Object>();
		if(!jsonDatas.isEmpty()){
			Map<String, Object> jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
			infusionBloodInfo = (Map<String, Object>)jsonMap.get("infusionBloodInfo");
			if(infusionBloodInfo == null){
				infusionBloodInfo = new HashMap<String, Object>();
			}
		}

		String infusionBloodInfoJson = JsonUtil.objectToJson(infusionBloodInfo);
		model.addAttribute("infusionBloodInfo", infusionBloodInfo);
		model.addAttribute("infusionBloodInfoJson", infusionBloodInfoJson);
		return "coding/edit_infusion_blood_info";
	}

	@SuppressWarnings("unchecked")
	@PostMapping("/edit_infusion_blood_info")
	public String editInfusionBloodInfo(InfusionBloodInfo infusionBloodInfo,HttpServletRequest request,Model model){
		try {

			String filePath = myConfig.getJsonRecourcePath() + StringUtil.getLocalPath(infusionBloodInfo.getVisitGuid())+infusionBloodInfo.getVisitGuid()+"\\";
			String versionFilePath = filePath+"version\\";
			String fileName = infusionBloodInfo.getVisitGuid() + ".json";
			String versionFileName = infusionBloodInfo.getVisitGuid()+"-" + DateUtil.dateFormat("yyyyMMddHHmmssssss", new Date()) + ".json";

			/*String jsonData = FileUtil.readFile(filePath, fileName);*/
			List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(infusionBloodInfo.getVisitGuid());
			Map<String, Object> jsonMap = new HashMap<String, Object>();
			if(!jsonDatas.isEmpty()){
				jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
				if(jsonMap == null){
					jsonMap = new HashMap<String, Object>();
				}
			}
			Subject subject=SecurityUtils.getSubject();
			Session session = subject.getSession();
			Map<String, Object> currentUser = (Map<String, Object>)session.getAttribute("currentUser");
			String userCode =(String)currentUser.get("user_code");
			String userName =(String)currentUser.get("user_name");
			jsonMap.put("userCode", userCode);
			jsonMap.put("userName", userName);
			jsonMap.put("infusionBloodInfo", infusionBloodInfo);
			String jsonMapJson = JsonUtil.objectToJson(jsonMap);
			FileUtil.createOrEditFile(jsonMapJson, filePath, fileName);
			FileUtil.createOrEditFile(jsonMapJson, versionFilePath, versionFileName);
			medicalRecordCodingService.editInfusionBloodInfo(infusionBloodInfo.getVisitGuid(), infusionBloodInfo, jsonMap);
			jsonMap = JsonUtil.jsonToPojo(jsonMapJson, Map.class);
			model.addAttribute("visitGuid", infusionBloodInfo.getVisitGuid());

			Map<String, Object> infusionBloodInfoMap = (Map<String, Object>)jsonMap.get("infusionBloodInfo");
			String infusionBloodInfoJson = JsonUtil.objectToJson(infusionBloodInfoMap);
			model.addAttribute("infusionBloodInfo", infusionBloodInfoMap);

			model.addAttribute("infusionBloodInfoJson",infusionBloodInfoJson);
			Map<String, List<Map<String, Object>>> baseInfo = baseInfoService.getBaseDataOfInfusionBloodInfo();
			String baseInfoJson = JsonUtil.objectToJson(baseInfo);
			model.addAttribute("baseInfoJson", baseInfoJson);
			RespondResult respondResult = new RespondResult(true,"200","保存成功",null);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			RespondResult respondResult = new RespondResult(false,"500","保存失败",null);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
		}
		return "coding/edit_infusion_blood_info";
	}

	@GetMapping("/edit_transfer_dept_info_form")
	public String editTransferDeptInfoForm(String visitGuid,Model model){

		model.addAttribute("visitGuid", visitGuid);
		Map<String, List<Map<String, Object>>> baseInfo = baseInfoService.getBaseInfoOfTransferDeptInfo();
		String baseInfoJson = JsonUtil.objectToJson(baseInfo);
		model.addAttribute("baseInfoJson", baseInfoJson);
		List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(visitGuid);

		Map<String, Object> transferDeptInfo = new HashMap<String, Object>();
		if(!jsonDatas.isEmpty()){
			Map<String, Object> jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
			transferDeptInfo = (Map<String, Object>)jsonMap.get("transferDeptInfo");
			if(transferDeptInfo == null){
				transferDeptInfo = new HashMap<String, Object>();
			}
		}

		String transferDeptInfoJson = JsonUtil.objectToJson(transferDeptInfo);
		model.addAttribute("transferDeptInfo", transferDeptInfo);
		model.addAttribute("transferDeptInfoJson", transferDeptInfoJson);
		return "coding/edit_transfer_dept_info";
	}

	@SuppressWarnings("unchecked")
	@PostMapping("/edit_transfer_dept_info")
	public String editTransferDeptInfoForm(TransferDeptInfo transferDeptInfo,HttpServletRequest request,Model model){
		try {

			String filePath = myConfig.getJsonRecourcePath() + StringUtil.getLocalPath(transferDeptInfo.getVisitGuid())+transferDeptInfo.getVisitGuid()+"\\";
			String versionFilePath = filePath+"version\\";
			String fileName = transferDeptInfo.getVisitGuid() + ".json";
			String versionFileName = transferDeptInfo.getVisitGuid()+"-" + DateUtil.dateFormat("yyyyMMddHHmmssssss", new Date()) + ".json";
			transferDeptInfo.clearEmpty();
			/*String jsonData = FileUtil.readFile(filePath, fileName);*/
			List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(transferDeptInfo.getVisitGuid());
			Map<String, Object> jsonMap = new HashMap<String, Object>();
			if(!jsonDatas.isEmpty()){
				jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
				if(jsonMap == null){
					jsonMap = new HashMap<String, Object>();
				}
			}
			Subject subject=SecurityUtils.getSubject();
			Session session = subject.getSession();
			Map<String, Object> currentUser = (Map<String, Object>)session.getAttribute("currentUser");
			String userCode =(String)currentUser.get("user_code");
			String userName =(String)currentUser.get("user_name");
			jsonMap.put("userCode", userCode);
			jsonMap.put("userName", userName);
			jsonMap.put("transferDeptInfo", transferDeptInfo);
			String jsonMapJson = JsonUtil.objectToJson(jsonMap);
			FileUtil.createOrEditFile(jsonMapJson, filePath, fileName);
			FileUtil.createOrEditFile(jsonMapJson, versionFilePath, versionFileName);
			medicalRecordCodingService.editTransferDeptInfo(transferDeptInfo.getVisitGuid(), transferDeptInfo, jsonMap);
			jsonMap = JsonUtil.jsonToPojo(jsonMapJson, Map.class);
			model.addAttribute("visitGuid", transferDeptInfo.getVisitGuid());

			Map<String, Object> transferDeptInfoMap = (Map<String, Object>)jsonMap.get("transferDeptInfo");
			String transferDeptInfoJson = JsonUtil.objectToJson(transferDeptInfoMap);
			model.addAttribute("transferDeptInfo", transferDeptInfoMap);

			model.addAttribute("transferDeptInfoJson",transferDeptInfoJson);
			Map<String, List<Map<String, Object>>> baseInfo = baseInfoService.getBaseInfoOfTransferDeptInfo();
			String baseInfoJson = JsonUtil.objectToJson(baseInfo);
			model.addAttribute("baseInfoJson", baseInfoJson);
			RespondResult respondResult = new RespondResult(true,"200","保存成功",null);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			RespondResult respondResult = new RespondResult(false,"500","保存失败",null);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
		}
		return "coding/edit_transfer_dept_info";
	}

	@GetMapping("/edit_drug_allergy_info_form")
	public String editDrugAllergyInfoForm(String visitGuid,Model model){

		model.addAttribute("visitGuid", visitGuid);
		Map<String, List<Map<String, Object>>> baseInfo = baseInfoService.getBaseDataOfDrugAllergyInfo();
		String baseInfoJson = JsonUtil.objectToJson(baseInfo);
		model.addAttribute("baseInfoJson", baseInfoJson);
		List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(visitGuid);

		Map<String, Object> drugAllergyInfo = new HashMap<String, Object>();
		if(!jsonDatas.isEmpty()){
			Map<String, Object> jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
			drugAllergyInfo = (Map<String, Object>)jsonMap.get("drugAllergyInfo");
			if(drugAllergyInfo == null){
				drugAllergyInfo = new HashMap<String, Object>();
			}
		}

		String drugAllergyInfoJson = JsonUtil.objectToJson(drugAllergyInfo);
		model.addAttribute("drugAllergyInfo", drugAllergyInfo);
		model.addAttribute("drugAllergyInfoJson",drugAllergyInfoJson);
		return "coding/edit_drug_allergy_info";
	}


	@SuppressWarnings("unchecked")
	@PostMapping("/edit_drug_allergy_info")
	public String editDrugAllergyInfo(DrugAllergyInfo drugAllergyInfo,HttpServletRequest request,Model model){
		try {

			String filePath = myConfig.getJsonRecourcePath() + StringUtil.getLocalPath(drugAllergyInfo.getVisitGuid())+drugAllergyInfo.getVisitGuid()+"\\";
			String versionFilePath = filePath+"version\\";
			String fileName = drugAllergyInfo.getVisitGuid() + ".json";
			String versionFileName = drugAllergyInfo.getVisitGuid()+"-" + DateUtil.dateFormat("yyyyMMddHHmmssssss", new Date()) + ".json";

			/*String jsonData = FileUtil.readFile(filePath, fileName);*/
			List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(drugAllergyInfo.getVisitGuid());
			Map<String, Object> jsonMap = new HashMap<String, Object>();
			if(!jsonDatas.isEmpty()){
				jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
				if(jsonMap == null){
					jsonMap = new HashMap<String, Object>();
				}
			}
			Subject subject=SecurityUtils.getSubject();
			Session session = subject.getSession();
			Map<String, Object> currentUser = (Map<String, Object>)session.getAttribute("currentUser");
			String userCode =(String)currentUser.get("user_code");
			String userName =(String)currentUser.get("user_name");
			jsonMap.put("userCode", userCode);
			jsonMap.put("userName", userName);
			jsonMap.put("drugAllergyInfo", drugAllergyInfo);
			String jsonMapJson = JsonUtil.objectToJson(jsonMap);
			FileUtil.createOrEditFile(jsonMapJson, filePath, fileName);
			FileUtil.createOrEditFile(jsonMapJson, versionFilePath, versionFileName);
			medicalRecordCodingService.editDrugAllergyInfo(drugAllergyInfo.getVisitGuid(), drugAllergyInfo, jsonMap);
			jsonMap = JsonUtil.jsonToPojo(jsonMapJson, Map.class);
			model.addAttribute("visitGuid", drugAllergyInfo.getVisitGuid());

			Map<String, Object> drugAllergyInfoMap = (Map<String, Object>)jsonMap.get("drugAllergyInfo");
			String drugAllergyInfoJson = JsonUtil.objectToJson(drugAllergyInfoMap);
			model.addAttribute("drugAllergyInfo",drugAllergyInfoMap);

			model.addAttribute("drugAllergyInfoJson",drugAllergyInfoJson);
			Map<String, List<Map<String, Object>>> baseInfo = baseInfoService.getBaseDataOfDrugAllergyInfo();
			String baseInfoJson = JsonUtil.objectToJson(baseInfo);
			model.addAttribute("baseInfoJson", baseInfoJson);
			RespondResult respondResult = new RespondResult(true,"200","保存成功",null);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			RespondResult respondResult = new RespondResult(false,"500","保存失败",null);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
		}

		return "coding/edit_drug_allergy_info";
	}


	@GetMapping("/edit_nurse_info_form")
	public String editNurseInfoForm(String visitGuid,Model model){
		model.addAttribute("visitGuid", visitGuid);
		List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(visitGuid);

		Map<String, Object> nurseInfo = new HashMap<String, Object>();
		if(!jsonDatas.isEmpty()){
			Map<String, Object> jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
			nurseInfo = (Map<String, Object>)jsonMap.get("nurseInfo");
			if(nurseInfo == null){
				nurseInfo = new HashMap<String, Object>();
			}
		}

		String nurseInfoJson = JsonUtil.objectToJson(nurseInfo);
		model.addAttribute("nurseInfo", nurseInfo);
		model.addAttribute("nurseInfoJson", nurseInfoJson);
		return "coding/edit_nurse_info";
	}

	@SuppressWarnings("unchecked")
	@PostMapping("/edit_nurse_info")
	public String editNurseInfo(NurseInfo nurseInfo,HttpServletRequest request,Model model){
		try {

			String filePath = myConfig.getJsonRecourcePath() + StringUtil.getLocalPath(nurseInfo.getVisitGuid())+nurseInfo.getVisitGuid()+"\\";
			String versionFilePath = filePath+"version\\";
			String fileName = nurseInfo.getVisitGuid() + ".json";
			String versionFileName = nurseInfo.getVisitGuid()+"-" + DateUtil.dateFormat("yyyyMMddHHmmssssss", new Date()) + ".json";

			/*String jsonData = FileUtil.readFile(filePath, fileName);*/
			List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(nurseInfo.getVisitGuid());
			Map<String, Object> jsonMap = new HashMap<String, Object>();
			if(!jsonDatas.isEmpty()){
				jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
				if(jsonMap == null){
					jsonMap = new HashMap<String, Object>();
				}
			}
			Subject subject=SecurityUtils.getSubject();
			Session session = subject.getSession();
			Map<String, Object> currentUser = (Map<String, Object>)session.getAttribute("currentUser");
			String userCode =(String)currentUser.get("user_code");
			String userName =(String)currentUser.get("user_name");
			jsonMap.put("userCode", userCode);
			jsonMap.put("userName", userName);
			jsonMap.put("nurseInfo", nurseInfo);
			String jsonMapJson = JsonUtil.objectToJson(jsonMap);
			FileUtil.createOrEditFile(jsonMapJson, filePath, fileName);
			FileUtil.createOrEditFile(jsonMapJson, versionFilePath, versionFileName);
			medicalRecordCodingService.editNurseInfo(nurseInfo.getVisitGuid(), nurseInfo, jsonMap);
			jsonMap = JsonUtil.jsonToPojo(jsonMapJson, Map.class);
			model.addAttribute("visitGuid", nurseInfo.getVisitGuid());

			Map<String, Object> nurseInfoMap = (Map<String, Object>)jsonMap.get("nurseInfo");
			String nurseInfoJson = JsonUtil.objectToJson(nurseInfoMap);
			model.addAttribute("nurseInfo", nurseInfoMap);

			model.addAttribute("nurseInfoJson",nurseInfoJson);
			RespondResult respondResult = new RespondResult(true,"200","保存成功",null);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			RespondResult respondResult = new RespondResult(false,"500","保存失败",null);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
		}

		return "coding/edit_nurse_info";
	}

	@GetMapping("/edit_intensive_care_info_form")
	public String editIntensiveCareInfoForm(String visitGuid,Model model){
		Map<String, List<Map<String, Object>>> baseInfo = baseInfoService.getBaseDataOfIntensiveCareInfo();
		String baseInfoJson = JsonUtil.objectToJson(baseInfo);
		model.addAttribute("baseInfoJson", baseInfoJson);
		model.addAttribute("visitGuid", visitGuid);
		List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(visitGuid);

		Map<String, Object> intensiveCareInfo = new HashMap<String, Object>();
		if(!jsonDatas.isEmpty()){
			Map<String, Object> jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
			intensiveCareInfo = (Map<String, Object>)jsonMap.get("intensiveCareInfo");
			if(intensiveCareInfo == null){
				intensiveCareInfo = new HashMap<String, Object>();
			}
		}

		String intensiveCareInfoJson = JsonUtil.objectToJson(intensiveCareInfo);
		model.addAttribute("intensiveCareInfo", intensiveCareInfo);
		model.addAttribute("intensiveCareInfoJson", intensiveCareInfoJson);
		return "coding/edit_intensive_care_info";
	}


	@SuppressWarnings("unchecked")
	@PostMapping("/edit_intensive_care_info")
	public String editIntensiveCareInfo(IntensiveCareInfo intensiveCareInfo,HttpServletRequest request,Model model){
		try {

			String filePath = myConfig.getJsonRecourcePath() + StringUtil.getLocalPath(intensiveCareInfo.getVisitGuid())+intensiveCareInfo.getVisitGuid()+"\\";
			String versionFilePath = filePath+"version\\";
			String fileName = intensiveCareInfo.getVisitGuid() + ".json";
			String versionFileName = intensiveCareInfo.getVisitGuid()+"-" + DateUtil.dateFormat("yyyyMMddHHmmssssss", new Date()) + ".json";

			/*String jsonData = FileUtil.readFile(filePath, fileName);*/
			List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(intensiveCareInfo.getVisitGuid());
			Map<String, Object> jsonMap = new HashMap<String, Object>();
			if(!jsonDatas.isEmpty()){
				jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
 				if(jsonMap == null){
					jsonMap = new HashMap<String, Object>();
				}
			}
 			Subject subject=SecurityUtils.getSubject();
			Session session = subject.getSession();
			Map<String, Object> currentUser = (Map<String, Object>)session.getAttribute("currentUser");
			String userCode =(String)currentUser.get("user_code");
			String userName =(String)currentUser.get("user_name");
 			jsonMap.put("userCode", userCode);
 			jsonMap.put("userName", userName);
 			jsonMap.put("intensiveCareInfo", intensiveCareInfo);
 			String jsonMapJson = JsonUtil.objectToJson(jsonMap);
 			FileUtil.createOrEditFile(jsonMapJson, filePath, fileName);
 			FileUtil.createOrEditFile(jsonMapJson, versionFilePath, versionFileName);
  			medicalRecordCodingService.editIntensiveCareInfo(intensiveCareInfo.getVisitGuid(), intensiveCareInfo, jsonMap);
  			jsonMap = JsonUtil.jsonToPojo(jsonMapJson, Map.class);
 			model.addAttribute("visitGuid", intensiveCareInfo.getVisitGuid());

 			Map<String, Object> intensiveCareInfoMap = (Map<String, Object>)jsonMap.get("intensiveCareInfo");
			String intensiveCareInfoJson = JsonUtil.objectToJson(intensiveCareInfoMap);
			model.addAttribute("intensiveCareInfo", intensiveCareInfoMap);

			model.addAttribute("intensiveCareInfoJson",intensiveCareInfoJson);
			RespondResult respondResult = new RespondResult(true,"200","保存成功",null);
			Map<String, List<Map<String, Object>>> baseInfo = baseInfoService.getBaseDataOfIntensiveCareInfo();
			String baseInfoJson = JsonUtil.objectToJson(baseInfo);
			model.addAttribute("baseInfoJson", baseInfoJson);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));

		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			RespondResult respondResult = new RespondResult(false,"500","保存失败",null);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
		}
		return "coding/edit_intensive_care_info";
	}

	@GetMapping("/edit_medical_ventilator_info_form")
	public String editMedicalVentilatorInfoForm(String visitGuid,Model model){
		model.addAttribute("visitGuid", visitGuid);
		List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(visitGuid);
		Map<String, List<Map<String, Object>>> baseInfo = baseInfoService.getBaseDataOfIntensiveCareInfo();
		String baseInfoJson = JsonUtil.objectToJson(baseInfo);
		model.addAttribute("baseInfoJson", baseInfoJson);
		Map<String, Object> medicalVentilatorInfo = new HashMap<String, Object>();
		if(!jsonDatas.isEmpty()){
			Map<String, Object> jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
			medicalVentilatorInfo = (Map<String, Object>)jsonMap.get("medicalVentilatorInfo");
			if(medicalVentilatorInfo == null){
				medicalVentilatorInfo = new HashMap<String, Object>();
			}
		}

		String medicalVentilatorInfoJson = JsonUtil.objectToJson(medicalVentilatorInfo);
		model.addAttribute("medicalVentilatorInfo", medicalVentilatorInfo);
		model.addAttribute("medicalVentilatorInfoJson", medicalVentilatorInfoJson);
		return "coding/edit_medical_ventilator_info";
	}


	@SuppressWarnings("unchecked")
	@PostMapping("/edit_medical_ventilator_info")
	public String editInfectionInfo(MedicalVentilatorInfo medicalVentilatorInfo,HttpServletRequest request,Model model){
		try {
			medicalVentilatorInfo.clearEmpty();
			Map<String, List<Map<String, Object>>> baseInfo = baseInfoService.getBaseDataOfIntensiveCareInfo();
			String baseInfoJson = JsonUtil.objectToJson(baseInfo);
			model.addAttribute("baseInfoJson", baseInfoJson);
			String filePath = myConfig.getJsonRecourcePath() + StringUtil.getLocalPath(medicalVentilatorInfo.getVisitGuid())+medicalVentilatorInfo.getVisitGuid()+"\\";
			String versionFilePath = filePath+"version\\";
			String fileName = medicalVentilatorInfo.getVisitGuid() + ".json";
			String versionFileName = medicalVentilatorInfo.getVisitGuid()+"-" + DateUtil.dateFormat("yyyyMMddHHmmssssss", new Date()) + ".json";

			/*String jsonData = FileUtil.readFile(filePath, fileName);*/
			List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(medicalVentilatorInfo.getVisitGuid());
			Map<String, Object> jsonMap = new HashMap<String, Object>();
			if(!jsonDatas.isEmpty()){
				jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
 				if(jsonMap == null){
					jsonMap = new HashMap<String, Object>();
				}
			}
 			Subject subject=SecurityUtils.getSubject();
			Session session = subject.getSession();
			Map<String, Object> currentUser = (Map<String, Object>)session.getAttribute("currentUser");
			String userCode =(String)currentUser.get("user_code");
			String userName =(String)currentUser.get("user_name");
 			jsonMap.put("userCode", userCode);
 			jsonMap.put("userName", userName);
 			jsonMap.put("medicalVentilatorInfo", medicalVentilatorInfo);
 			String jsonMapJson = JsonUtil.objectToJson(jsonMap);
 			FileUtil.createOrEditFile(jsonMapJson, filePath, fileName);
 			FileUtil.createOrEditFile(jsonMapJson, versionFilePath, versionFileName);
  			medicalRecordCodingService.editMedicalVentilatorInfo(medicalVentilatorInfo.getVisitGuid(), medicalVentilatorInfo, jsonMap);
  			jsonMap = JsonUtil.jsonToPojo(jsonMapJson, Map.class);
 			model.addAttribute("visitGuid", medicalVentilatorInfo.getVisitGuid());

 			Map<String, Object> medicalVentilatorInfoMap = (Map<String, Object>)jsonMap.get("medicalVentilatorInfo");
			String medicalVentilatorInfoJson = JsonUtil.objectToJson(medicalVentilatorInfoMap);
			model.addAttribute("medicalVentilatorInfo", medicalVentilatorInfoMap);

			model.addAttribute("medicalVentilatorInfoJson",medicalVentilatorInfoJson);
			RespondResult respondResult = new RespondResult(true,"200","保存成功",null);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			RespondResult respondResult = new RespondResult(false,"500","保存失败",null);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
		}
		return "coding/edit_medical_ventilator_info";
	}


	@GetMapping("/edit_infection_info_form")
	public String editInfectionInfoForm(String visitGuid,Model model){
		model.addAttribute("visitGuid", visitGuid);
		List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(visitGuid);

		Map<String, Object> infectionInfo = new HashMap<String, Object>();
		if(!jsonDatas.isEmpty()){
			Map<String, Object> jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
			infectionInfo = (Map<String, Object>)jsonMap.get("infectionInfo");
			if(infectionInfo == null){
				infectionInfo = new HashMap<String, Object>();
			}
		}

		String infectionInfoJson = JsonUtil.objectToJson(infectionInfo);
		model.addAttribute("infectionInfo", infectionInfo);
		model.addAttribute("infectionInfoJson", infectionInfoJson);
		return "coding/edit_infection_info";
	}

	@SuppressWarnings("unchecked")
	@PostMapping("/edit_infection_info")
	public String editInfectionInfo(InfectionInfo infectionInfo,HttpServletRequest request,Model model){
		try {

			String filePath = myConfig.getJsonRecourcePath() + StringUtil.getLocalPath(infectionInfo.getVisitGuid())+infectionInfo.getVisitGuid()+"\\";
			String versionFilePath = filePath+"version\\";
			String fileName = infectionInfo.getVisitGuid() + ".json";
			String versionFileName = infectionInfo.getVisitGuid()+"-" + DateUtil.dateFormat("yyyyMMddHHmmssssss", new Date()) + ".json";

			/*String jsonData = FileUtil.readFile(filePath, fileName);*/
			List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(infectionInfo.getVisitGuid());
			Map<String, Object> jsonMap = new HashMap<String, Object>();
			if(!jsonDatas.isEmpty()){
				jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
 				if(jsonMap == null){
					jsonMap = new HashMap<String, Object>();
				}
			}
 			Subject subject=SecurityUtils.getSubject();
			Session session = subject.getSession();
			Map<String, Object> currentUser = (Map<String, Object>)session.getAttribute("currentUser");
			String userCode =(String)currentUser.get("user_code");
			String userName =(String)currentUser.get("user_name");
 			jsonMap.put("userCode", userCode);
 			jsonMap.put("userName", userName);
 			jsonMap.put("infectionInfo", infectionInfo);
 			String jsonMapJson = JsonUtil.objectToJson(jsonMap);
 			FileUtil.createOrEditFile(jsonMapJson, filePath, fileName);
 			FileUtil.createOrEditFile(jsonMapJson, versionFilePath, versionFileName);
  			medicalRecordCodingService.editInfectionInfo(infectionInfo.getVisitGuid(), infectionInfo, jsonMap);
  			jsonMap = JsonUtil.jsonToPojo(jsonMapJson, Map.class);
 			model.addAttribute("visitGuid", infectionInfo.getVisitGuid());

 			Map<String, Object> infectionInfoMap = (Map<String, Object>)jsonMap.get("infectionInfo");
			String infectionInfoJson = JsonUtil.objectToJson(infectionInfoMap);
			model.addAttribute("infectionInfo", infectionInfoMap);

			model.addAttribute("infectionInfoJson",infectionInfoJson);
			RespondResult respondResult = new RespondResult(true,"200","保存成功",null);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			RespondResult respondResult = new RespondResult(false,"500","保存失败",null);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
		}
		return "coding/edit_infection_info";
	}

	@GetMapping("/edit_cost_info_form")
	public String editCostInfoForm(String visitGuid,Model model){
		model.addAttribute("visitGuid", visitGuid);
		List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(visitGuid);

		Map<String, Object> costInfo = new HashMap<String, Object>();
		if(!jsonDatas.isEmpty()){
			Map<String, Object> jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
			costInfo = (Map<String, Object>)jsonMap.get("costInfo");
			if(costInfo == null){
				costInfo = new HashMap<String, Object>();
			}
		}

		String costInfoJson = JsonUtil.objectToJson(costInfo);
		model.addAttribute("costInfo", costInfo);
		model.addAttribute("costInfoJson", costInfoJson);
		return "coding/edit_cost_info";
	}

	@SuppressWarnings("unchecked")
	@PostMapping("/edit_cost_info")
	public String editCostInfo(CostInfo costInfo,HttpServletRequest request,Model model){
		try {

			String filePath = myConfig.getJsonRecourcePath() + StringUtil.getLocalPath(costInfo.getVisitGuid())+costInfo.getVisitGuid()+"\\";
			String versionFilePath = filePath+"version\\";
			String fileName = costInfo.getVisitGuid() + ".json";
			String versionFileName = costInfo.getVisitGuid()+"-" + DateUtil.dateFormat("yyyyMMddHHmmssssss", new Date()) + ".json";

			/*String jsonData = FileUtil.readFile(filePath, fileName);*/
			List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(costInfo.getVisitGuid());
			Map<String, Object> jsonMap = new HashMap<String, Object>();
			if(!jsonDatas.isEmpty()){
				jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
 				if(jsonMap == null){
					jsonMap = new HashMap<String, Object>();
				}
			}
 			Subject subject=SecurityUtils.getSubject();
			Session session = subject.getSession();
			Map<String, Object> currentUser = (Map<String, Object>)session.getAttribute("currentUser");
			String userCode =(String)currentUser.get("user_code");
			String userName =(String)currentUser.get("user_name");
 			jsonMap.put("userCode", userCode);
 			jsonMap.put("userName", userName);
 			jsonMap.put("costInfo", costInfo);
 			String jsonMapJson = JsonUtil.objectToJson(jsonMap);
 			FileUtil.createOrEditFile(jsonMapJson, filePath, fileName);
 			FileUtil.createOrEditFile(jsonMapJson, versionFilePath, versionFileName);
  			medicalRecordCodingService.editCostInfo(costInfo.getVisitGuid(), costInfo, jsonMap);
  			jsonMap = JsonUtil.jsonToPojo(jsonMapJson, Map.class);
 			model.addAttribute("visitGuid", costInfo.getVisitGuid());

 			Map<String, Object> costInfoMap = (Map<String, Object>)jsonMap.get("costInfo");
			String costInfoJson = JsonUtil.objectToJson(costInfoMap);
			model.addAttribute("costInfo", costInfoMap);

			model.addAttribute("costInfoJson",costInfoJson);
			RespondResult respondResult = new RespondResult(true,"200","保存成功",null);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			RespondResult respondResult = new RespondResult(false,"500","保存失败",null);
			model.addAttribute("respondResultJson", JsonUtil.objectToJson(respondResult));
		}
		return "coding/edit_cost_info";
	}


	@PostMapping("/ajax_coding_finish")
	@ResponseBody
	public RespondResult ajaxCodingFinish(String visitGuid){
		RespondResult respondResult = null;
		String errorMessage = null;
		try{

			errorMessage = medicalRecordCodingService.codingFinish(visitGuid);
			if(errorMessage == null){
				respondResult = new RespondResult(true, RespondResult.successCode, null, null);
			}else{
				respondResult = new RespondResult(true, RespondResult.errorCode, errorMessage, errorMessage);
			}

		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			respondResult = new RespondResult(false, RespondResult.errorCode, e.getMessage(), "编码完成失败");
		}

		return respondResult;
	}

	@GetMapping("/show_home_page_index")
	public void homePagePrint(String visitGuid, Model model, HttpServletRequest request,HttpServletResponse response) {
		Subject subject=SecurityUtils.getSubject();
		Session session = subject.getSession();
		Map<String, Object> currentUser = (Map<String, Object>)session.getAttribute("currentUser");
		ByteArrayOutputStream baos = null;
		try {
			//visitGuid = "53f94d7cdaf8435ebc924cf541576eea";
			List<String> jsonDatas = medicalRecordCodingService.getMedicalRecordJsonByVisitGuid(visitGuid);
			Map<String, Object> jsonMap = new HashMap<String, Object>();
			Map<String, Object> basicInfo = new HashMap<String, Object>();
			if(!jsonDatas.isEmpty()){
				jsonMap = JsonUtil.jsonToPojo(jsonDatas.get(0), Map.class);
				basicInfo = (Map<String, Object>)jsonMap.get("basicInfo");
			}

			if(basicInfo == null){

				basicInfo = new HashMap<String, Object>();
				MedicalRecord medicalRecord = medicalRecordService.selectMedicalRecordByPrimaryKey(visitGuid);

				String patientName = medicalRecord.getPatientName();
				basicInfo.put("patientName",patientName);

				String sexCode = medicalRecord.getSexCode();
				basicInfo.put("sexCode",sexCode);

				String sexName = medicalRecord.getSexName();
				basicInfo.put("sexName",sexName);

				Date birthday = medicalRecord.getBirthday();
				if(birthday != null){
					basicInfo.put("birthday", DateUtil.dateFormat(birthday));
				}
				String documentTypeCode = medicalRecord.getDocumentTypeCode();
				basicInfo.put("documentTypeCode",documentTypeCode);

				String documentTypeName = medicalRecord.getDocumentTypeName();
				basicInfo.put("documentTypeName",documentTypeName);

				String idNumber = medicalRecord.getIdNumber();
				basicInfo.put("idNumber",idNumber);


				String inDeptCode = medicalRecord.getInDeptCode();
				basicInfo.put("inDeptCode",inDeptCode);

				String inDeptName = medicalRecord.getInDeptName();
				basicInfo.put("inDeptName",inDeptName);

				Date inHospitalDateTime = medicalRecord.getInHospitalDateTime();
				if(inHospitalDateTime != null){
					basicInfo.put("inHospitalDateTime", DateUtil.dateFormat(DateUtil.DATE_TIME_FORMATE,inHospitalDateTime));
				}

				Date outHospitalDateTime = medicalRecord.getOutHospitalDateTime();
				if(outHospitalDateTime != null){
					basicInfo.put("outHospitalDateTime", DateUtil.dateFormat(DateUtil.DATE_TIME_FORMATE,outHospitalDateTime));
				}
				String outDeptCode = medicalRecord.getOutDeptCode();
				basicInfo.put("outDeptCode",outDeptCode);

				String outDeptName = medicalRecord.getOutDeptName();
				basicInfo.put("outDeptName",outDeptName);

				String outHospitalTypeCode = medicalRecord.getOutHospitalTypeCode();
				basicInfo.put("outHospitalTypeCode",outHospitalTypeCode);

				String outHospitalTypeName = medicalRecord.getOutHospitalTypeName();
				basicInfo.put("outHospitalTypeName",outHospitalTypeName);

				String mrId = medicalRecord.getMrId();
				basicInfo.put("mrId",mrId);

				String onlyId = medicalRecord.getOnlyId();
				basicInfo.put("onlyId",onlyId);

				Integer visitNumber = medicalRecord.getVisitNumber();
				basicInfo.put("visitNumber",visitNumber);

				jsonMap.put("basicInfo", basicInfo);
			}
			baos = PDFUtil.getPDFStreamByTemplate(jsonMap, myConfig.getPageIndexpPdfTemplatePath(),null);
			/*ByteArrayOutputStream out = WaterMarkUtil.getOutputStreamOfWterMarkByText(baos, (String)currentUser.get("user_code"));
			*//*ByteArrayOutputStream out = WaterMarkUtil.getOutputStreamOfWterMarkByIcon(baos, "D:\\publics\\medical_record\\water_icon\\305logo.jpg");*/
			response.setContentLength(baos.size());
			response.setContentType("application/pdf");
			response.addHeader("Content-Disposition", "inline;FileName=out.pdf");

			OutputStream outStream = response.getOutputStream();
	        outStream.write(baos.toByteArray(), 0, baos.size());
	        outStream.flush();
	        outStream.close();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	@GetMapping("/main_disease_diag_check_page")
	public String mainDiseaseDiagCheck(Model model){
		return "check/main_disease_diag_check_page";
	}


	@GetMapping("/ajax_main_disease_diag_check")
	@ResponseBody
	public RespondResult ajaxMainDiseaseDiagCheck(MedicalRecordQuery params){
		RespondResult respondResult = null;

		try{
			List<Map<String,Object>> medicalRecords = new ArrayList<Map<String,Object>>();
			if(!params.queryUnEncodingEmpty()){
				medicalRecords = medicalRecordCodingService.mainDiseaseDiagCheck(params);
			}

			respondResult = new RespondResult(true, RespondResult.successCode, null, medicalRecords);
		}catch (Exception e) {
			// TODO: handle exception
			respondResult = new RespondResult(false, RespondResult.errorCode, e.getMessage(), "");
		}

		return respondResult;
	}

	@GetMapping("/in_hospital_day_number_check_page")
	public String inHospitalDayNumberCheck(Model model){
		return "check/in_hospital_day_number_check_page";
	}

	@GetMapping("/in_hospital_day_number_check")
	@ResponseBody
	public RespondResult ajaxInHospitalDayNumberCheck(MedicalRecordQuery params){
		RespondResult respondResult = null;

		try{
			List<Map<String,Object>> medicalRecords = new ArrayList<Map<String,Object>>();
			if(!params.queryUnEncodingEmpty()){
				medicalRecords = medicalRecordCodingService.inHospitalDayNumberCheck(params);
			}

			respondResult = new RespondResult(true, RespondResult.successCode, null, medicalRecords);
		}catch (Exception e) {
			// TODO: handle exception
			respondResult = new RespondResult(false, RespondResult.errorCode, e.getMessage(), "");
		}

		return respondResult;
	}

	@GetMapping("/repeat_coding_check_page")
	public String repeatCodingCheckCheck(Model model){
		return "check/repeat_coding_check_page";
	}

	@GetMapping("/ajax_repeat_coding_check")
	@ResponseBody
	public RespondResult ajaxRepeatCodingCheckCheck(MedicalRecordQuery params){
		RespondResult respondResult = null;

		try{
			List<Map<String,Object>> medicalRecords = new ArrayList<Map<String,Object>>();
			if(!params.queryUnEncodingEmpty()){
				medicalRecords = medicalRecordCodingService.repeatCodingCheck(params);
			}

			respondResult = new RespondResult(true, RespondResult.successCode, null, medicalRecords);
		}catch (Exception e) {
			// TODO: handle exception
			respondResult = new RespondResult(false, RespondResult.errorCode, e.getMessage(), "");
		}

		return respondResult;
	}

	@GetMapping("/date_time_check_page")
	public String dateTimeCheckCheck(Model model){
		return "check/date_time_check_page";
	}


	@GetMapping("/ajax_date_time_check")
	@ResponseBody
	public RespondResult ajaxDateTimeCheckCheck(MedicalRecordQuery params){
		RespondResult respondResult = null;

		try{
			List<Map<String,Object>> medicalRecords = new ArrayList<Map<String,Object>>();
			if(!params.queryUnEncodingEmpty()){
				medicalRecords = medicalRecordCodingService.dateTimeCheck(params);
			}

			respondResult = new RespondResult(true, RespondResult.successCode, null, medicalRecords);
		}catch (Exception e) {
			// TODO: handle exception
			respondResult = new RespondResult(false, RespondResult.errorCode, e.getMessage(), "");
		}

		return respondResult;
	}

	@GetMapping("/medical_record_repair_page")
	public String medicalRecordRepairPage(){
		return "coding/medical_record_repair_page";
	}


	@GetMapping("/query_repair_medical_record")
	@ResponseBody
	public RespondResult queryRepairMedicalRecord(MedicalRecordQuery params){
		RespondResult respondResult = null;

		try{
			List<Map<String,Object>> medicalRecords = new ArrayList<Map<String,Object>>();
			int count = 0;
			if(!params.queryUnEncodingEmpty()){
				medicalRecords = medicalRecordCodingService.getMedicalRecordOfRepair(params);
				count = medicalRecordCodingService.getMedicalRecordCountOfRepair(params);
			}

			params.setTotalCounts(count);
			params.setQueryDatas(medicalRecords);
			respondResult = new RespondResult(true, RespondResult.successCode, null, params);
		}catch (Exception e) {
			// TODO: handle exception
			respondResult = new RespondResult(false, RespondResult.errorCode, e.getMessage(), params);
		}

		return respondResult;
	}

	@GetMapping("/coding_defect_page")
	public String codingDefectPage(Model model){
		return "coding/coding_defect_page";
	}


	@GetMapping("/query_coding_defect")
	@ResponseBody
	public RespondResult queryCodingDefect(StatisticsAnalysisQuery params){
		RespondResult respondResult = null;

		try{
			List<Map<String,Object>> medicalRecordDefects = new ArrayList<Map<String,Object>>();
			medicalRecordDefects = medicalRecordCodingService.getMedicalRecordOfDefect(params);

			respondResult = new RespondResult(true, RespondResult.successCode, null, medicalRecordDefects);
		}catch (Exception e) {
			// TODO: handle exception
			respondResult = new RespondResult(false, RespondResult.errorCode, e.getMessage(), e);
		}

		return respondResult;
	}


	@GetMapping("/query_coding_defect_detail")
	@ResponseBody
	public RespondResult queryCodingDefectDetail(StatisticsAnalysisQuery params){
		RespondResult respondResult = null;

		try{
			List<Map<String,Object>> defectDetails = new ArrayList<Map<String,Object>>();
			defectDetails = medicalRecordCodingService.getMedicalRecordOfDefectDetail(params);

			respondResult = new RespondResult(true, RespondResult.successCode, null, defectDetails);
		}catch (Exception e) {
			// TODO: handle exception
			respondResult = new RespondResult(false, RespondResult.errorCode, e.getMessage(), e);
		}

		return respondResult;
	}


	/*@GetMapping("/syncSelfCost")
	@ResponseBody
	public RespondResult syncSelfCost(){
		RespondResult respondResult = null;
		MedicalRecordQuery params = new MedicalRecordQuery();
		try{
			params.setOutHospitalStartDate(DateUtil.dateParse("yyyy-MM-dd", "2019-01-01"));
			params.setOutHospitalEndDate(DateUtil.dateParse("yyyy-MM-dd", "2020-07-15"));
			List<MedicalRecord> medicalRecords = medicalRecordService.getAllMedicalRecord();
			int successCount = 0;
			for (MedicalRecord medicalRecord : medicalRecords) {
				Map<String, String> param = new HashMap<String, String>();
				param.put("visitGuid", medicalRecord.getVisitGuid());
				param.put("mrId", medicalRecord.getMrId());
				param.put("onlyId", medicalRecord.getOnlyId());
				String onlyId = medicalRecord.getOnlyId();
				String visitGuid = medicalRecord.getVisitGuid();
				int count = 0;

				if(onlyId != null){
					if(!(onlyId.contains("N") && onlyId.length() ==8)){
						String userJson = HttpClientUtil.doGet("http://localhost:8083/MedicalRecordInterface/interface_data_qf_dr/remote_extract_interface_cost", param);
						if(userJson != null){
							JSONObject userMap =JSONObject.parseObject(userJson);
							boolean success = userMap.getBoolean("success");
							if(success){

								Map<String, Object> jsonMap = (Map<String, Object>)userMap.get("datas");
								Map<String, Object> costMap = (Map<String, Object>)jsonMap.get("costInfo");
								count = interfaceMedicalRecord1Service.extractInterfaceMedicalRecordOfCost(visitGuid, costMap);
								if(count != 1){
									System.err.println(onlyId+"提取费用失败");
								}else{
									successCount++;
									System.out.println("更新成功第"+successCount+"条信息!");
								}

							}else{
								String stateMessage = userMap.getString("stateMessage");
								if(stateMessage == null){
									stateMessage = "访问接口应用失败";
								}
								System.err.println(onlyId+"提取费用失败");
							}
						}else{
							System.err.println(onlyId+"提取费用失败");
						}
					}
				}

			}


			respondResult = new RespondResult(true, RespondResult.successCode, null, successCount);
		}catch (Exception e) {
			// TODO: handle exception
			respondResult = new RespondResult(false, RespondResult.errorCode, e.getMessage(), e);
		}

		return respondResult;
	}

	*/



}
